import 'package:flutter/material.dart';
// 导入页面
import '/movie/list.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  static const img = "https://www.zym88.cn/wp-content/uploads/2022/09/a00f65b8e9154917-150x150.jpg";
  static const bg = "https://www.zym88.cn/wp-content/uploads/2022/03/0c4eaff5f1f8.jpg";

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '学习项目',
      theme: ThemeData(
        primarySwatch: Colors.purple,
      ),
      home: const MyHome(),
    );
  }
}

class MyHome extends StatelessWidget {
  const MyHome({super.key});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('首页'),
          centerTitle: true,
          // 右侧行为按钮
          actions: [
            IconButton(
              icon: const Icon(Icons.search),
              onPressed: () {
                print('点击了搜索按钮');
              },
            ),
          ],
        ),
        drawer: Drawer(
          child: ListView(
            padding: const EdgeInsets.all(0),
            children: const [
              UserAccountsDrawerHeader(
                currentAccountPicture: CircleAvatar(
                  backgroundImage: NetworkImage(MyApp.img),
                ),
                accountName: Text("张三"),
                accountEmail: Text("2327972001@qq.com"),
                decoration: BoxDecoration(
                  color: Colors.purple,
                  image: DecorationImage(
                    image: NetworkImage(MyApp.bg),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              ListTile(
                leading: Icon(
                  Icons.feedback,
                  color: Colors.purple,
                ),
                title: Text("用户反馈"),
              ),
              ListTile(
                leading: Icon(
                  Icons.settings,
                  color: Colors.purple,
                ),
                title: Text("系统设置"),
              ),
              ListTile(
                leading: Icon(
                  Icons.send,
                  color: Colors.purple,
                ),
                title: Text("发布电影"),
              ),
              Divider(
                color: Colors.purple,
              ),
              ListTile(
                leading: Icon(
                  Icons.logout,
                  color: Colors.purple,
                ),
                title: Text("退出登录"),
              ),
            ],
          ),
        ),
        bottomNavigationBar: Container(
          height: 50, // 一般高度都是50
          decoration: const BoxDecoration(color: Colors.purple),
          child: const TabBar(
            indicatorColor: Colors.white,
            labelStyle: TextStyle(
              height: 0,
              fontSize: 10,
            ),
            tabs: [
              Tab(
                iconMargin: EdgeInsets.only(top: 5),
                icon: Icon(Icons.home),
                text: "首页",
              ),
              Tab(
                iconMargin: EdgeInsets.only(top: 5),
                icon: Icon(Icons.movie),
                text: "电影",
              ),
              Tab(
                iconMargin: EdgeInsets.only(top: 5),
                icon: Icon(Icons.book),
                text: "图书",
              ),
            ],
          ),
        ),
        body: const TabBarView(
          // 禁止滑动
          physics: NeverScrollableScrollPhysics(),
          children: [
            MovieList(title: "coming_soon"),
            MovieList(title: "in_theaters"),
            MovieList(title: "top250"),
          ],
        ),
      ),
    );
  }
}
